-- -*-Haskell-*-

{-
 * Copyright (c) 2007 Gabor Greif
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is furnished to do
 * so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
 * OR OTHER DEALINGS IN THE SOFTWARE.
 -}

import "LangPrelude.prg"


exclude :: Tag ~> Row Tag * ~> Row Tag *
{exclude o RNil} = RNil
{exclude `a (RCons `a v r)} = {exclude `a r} -- BUG (issue41)
{exclude `b (RCons `b v r)} = {exclude `b r}
{exclude `c (RCons `c v r)} = {exclude `c r}
{exclude `b (RCons `a v r)} = RCons `a v {exclude `b r}
{exclude `c (RCons `a v r)} = RCons `a v {exclude `c r}
{exclude `a (RCons `b v r)} = RCons `b v {exclude `a r}
{exclude `c (RCons `b v r)} = RCons `b v {exclude `c r}
{exclude `a (RCons `c v r)} = RCons `c v {exclude `a r}
{exclude `b (RCons `c v r)} = RCons `c v {exclude `b r}


data SingleLabel :: Row Tag * ~> * where
  None :: SingleLabel RNil
  More :: Equal {exclude l rest} rest => Label l -> t -> SingleLabel rest -> SingleLabel {l=t;rest}r
 deriving Record(s)

t1 :: SingleLabel {`a=Int}r
t1 = {`a=25}s

##test "not solvable"
 t2 = {`a=25;undefined}s

t3 = {`a=25,`b=42}s

##test "duplicate tags"
 t4 = {`a=25,`a=25}s


-- Some basic operations on SingleLabel records:
------------------------------------------------

--- separate the head of the record and assemble it again after that.


apart :: SingleLabel row -> Maybe (Label a, v, tail, Equal {a=v; tail}s, row)
apart {}s = Nothing
apart {l=v; rest}s = Just (l, v, rest, Eq)

{-
**** Near line: 66 column: 1

While parsing a type constructor, unknown type: More, at line: 89 column: 1
-}

